#!/bin/bash

HOOKER_DRIVER=$(cat .hooker_driver)
while :
do
	frida-ps $HOOKER_DRIVER -ai | grep -v '@' | grep -v '    -  '
	echo "Enter the need to attach package."
    read -p ": " package
    if [[ $package = ex ]] || [[ $package = exit ]] || [[ $package = quit ]] || [[ $package = q ]]; then
		break
	fi
	echo "It's $package that you have attached app."
	python3 hooker.py -p $package -g true
	echo "--------------------------------------------------"
	while :
	do
		echo "Please enter e, s, j, c or ex command."
		echo "a: Discovering activities."
		echo "b: Discovering services."
		echo "c: Discovering object. eg:'c {objectId}'"
		echo "d: Object2Explain. eg:'d {objectId}'"
		echo "v: Discovering view. eg:'v {viewId}'"
		echo "e: Determines whether a class exists. eg:'e android.app.Application'"
		echo "s: Discovering classes by a class'regex. eg:'s com.tencent.mm.Message.*'"
		echo "t: Discovering offspring classes by a class'name. eg:'t com.tencent.mm.BasicActivity'"
		echo "j: Generating hooked js. eg:'j okhttp3.Request\$Builder:build'"
		echo "k: Generating hooked the string generation js with a keyword. eg:'k {YourKeyword}'"
		echo "l: Generating hooked the param generation js with a param keyword. eg:'l {YourKeyword}'"
		echo "m: Discovering so module."
		echo "ex: Exit to the upper layer. eg:'ex'"
		read -p ": " op
		if [[ $op = ex ]] || [[ $op = exit ]]; then
			break 
		fi
		if [[ $op = a ]] || [[ $op = b ]]; then
			python3 hooker.py -p $package -$op true
			continue
		fi
		if [[ $op =~ ^v ]] || [[ $op =~ ^l ]] || [[ $op =~ ^c ]] || [[ $op =~ ^d ]] || [[ $op =~ ^s ]] || [[ $op =~ ^t ]] || [[ $op =~ ^e ]] || [[ $op =~ ^j ]] || [[ $op =~ ^k ]] || [[ $op =~ ^m ]] ;then
			python3 hooker.py -p $package -$op
			continue
		fi
		echo "Wronging command!"
	done
done